
TOOL.Category		= "Render"
TOOL.Name			= "#Colour"
TOOL.Command		= nil
TOOL.ConfigName		= nil


TOOL.ClientConVar[ "r" ] = 255
TOOL.ClientConVar[ "g" ] = 0
TOOL.ClientConVar[ "b" ] = 255
TOOL.ClientConVar[ "a" ] = 255
TOOL.ClientConVar[ "mode" ] = 0
TOOL.ClientConVar[ "fx" ] = 0

function TOOL:LeftClick( trace )

	if trace.Entity && 		// Hit an entity
	   trace.Entity:IsValid() && 	// And the entity is valid
	   trace.Entity:EntIndex() != 0 // And isn't worldspawn
	then

		if (CLIENT) then
			return true 
		end
	
		local r		= self:GetClientNumber( "r", 0 )
		local g		= self:GetClientNumber( "g", 0 )
		local b		= self:GetClientNumber( "b", 0 )
		local a		= self:GetClientNumber( "a", 0 )
		local mode	= self:GetClientNumber( "mode", 0 )
		local fx	= self:GetClientNumber( "fx", 0 )

		SetColour( self:GetOwner(), trace.Entity, r, g, b, a, mode, fx)

		return true
		
	end
	
end

function TOOL:RightClick( trace )

	if trace.Entity && 		// Hit an entity
	   trace.Entity:IsValid() && 	// And the entity is valid
	   trace.Entity:EntIndex() != 0 // And isn't worldspawn
	then

		trace.Entity:SetKeyValue("renderfx", 0)
		trace.Entity:SetRenderMode(0)
		trace.Entity:SetColor(255, 255, 255, 255)
		trace.Entity:GetTable().colour = nil
	
		return true
	
	end
	
end

function SetColour( pl, Ent, r,g,b,a, mode, fx )

	Ent:SetColor( r,g,b, a )
	Ent:SetRenderMode(mode)
	Ent:SetKeyValue("renderfx", fx)

	local etable = {
			r = r,
			g = g,
			b = b,
			a = a,
			mode = mode,
			fx = fx
			}

	Ent:GetTable().colour = etable

	return true
end
duplicator.RegisterEntityModifier( "colour", SetColour, "r","g","b","a", "mode", "fx" )
